<?php require 'cabesario.php'; ?>
<?php
if ($_POST != null) {
    $login = $_POST['ip_login'];
    $senha = $_POST['ip_senha'];
    
    $user = new User();
    if($user->validAuthentication($login, $senha)){
        session_start();
        $_SESSION["autenticacao"] = "ok";
        $_SESSION["usuario"] = $user;
        $_SESSION["message"] = array('type'=>'ok','message'=>"Seja bem vindo - ".$user->getName());
        header("location: mycontacts.php");
    } else {
        echo '<div id="message" class="error">Nome de usuário ou senha errados. Por favor tente outra vez.</div>';
    }
}

if ($_GET != null) {
    $session = $_GET['session'];
    if ($session == 'stop') {
        session_start();
        session_destroy();
        header("location: index.php");
    }
}
?>

<form id="formularios" method="post" action="login.php">
    <input type="hidden" name="ip_redirect">
    <input class="input_text"type="text" placeholder="login" name="ip_login" required="true"></br>
    <input class="input_text" type="password" placeholder="senha" name="ip_senha" required="true"><br/><hr/>
    <input class="style_button" type="submit" value="LogIn">
    <a class="link_style" href="user.php">Cadastra-se</a>
</form>

<?php require 'rodape.php'; ?>